//
//  WDJWebController.m
#import "WDJWebController.h"
#import <WebKit/WebKit.h>
@interface WDJWebController ()
@property (nonatomic, strong) WKWebView *wdjWebView;
@property (nonatomic,strong) UILabel * wdjTitleLab;
@end

@implementation WDJWebController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = true;
    [self wdjCreatView];
//    [self.wdjWebView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];
    [self updataWebUrl];
}
- (void)wdjCreatView{
    _wdjWebView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:[[WKWebViewConfiguration alloc] init]];
    _wdjWebView.scrollView.backgroundColor = UIColor.clearColor;
    _wdjWebView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    [self.view addSubview:_wdjWebView];
    [_wdjWebView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@([WDjWholeData wholeScreewRatio:0]));
    }];
    UIButton * wdjBackBtn = [[UIButton alloc] init];
    if (_isWhiteBack) {
        self.view.backgroundColor = [WDjWholeData wholeColorHexString:@"#060B22"];
        self.wdjWebView.backgroundColor = [WDjWholeData wholeColorHexString:@"#060B22"];
        self.wdjWebView.opaque = NO;
        [wdjBackBtn setBackgroundImage:[WDjWholeData wholeImageNamed:@"wdj_NavBack"] forState:UIControlStateNormal];
    }else{
        self.view.backgroundColor = [WDjWholeData wholeColorHexString:@"#FFFFFF"];
        self.wdjWebView.backgroundColor = [WDjWholeData wholeColorHexString:@"#FFFFFF"];
        self.wdjWebView.opaque = NO;
        [wdjBackBtn setBackgroundImage:[WDjWholeData wholeImageNamed:@"wdj_webBackIcon"] forState:UIControlStateNormal];
    }
    [wdjBackBtn addTarget:self action:@selector(wdjBack) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:wdjBackBtn];
    [wdjBackBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([WDjWholeData wholeScreewRatio:24]));
        make.height.equalTo(@([WDjWholeData wholeScreewRatio:64]));
        make.width.equalTo(@([WDjWholeData wholeScreewRatio:64]));
        make.top.equalTo(@([WDjWholeData wholeScreewRatio:12]+[WDjWholeData wholeTopSafeH]));
    }];
    self.wdjTitleLab = [[UILabel alloc] init];
    self.wdjTitleLab.font = [UIFont systemFontOfSize:[WDjWholeData wholeScreewRatio:34] weight:UIFontWeightRegular];
    self.wdjTitleLab.textColor = [WDjWholeData wholeColorHexString:@"#FFFFFF"];
    [self.view addSubview:self.wdjTitleLab];
    [self.wdjTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(wdjBackBtn);
        make.centerX.equalTo(self.view);
        make.height.equalTo(@([WDjWholeData wholeScreewRatio:50]));
    }];
}
- (void)updataWebUrl{
    if(_wdjWebUrl.length > 0){
        NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:_wdjWebUrl]];
        [self.wdjWebView loadRequest:request];
    }
}
- (void)wdjBack{
    [self.navigationController popViewControllerAnimated:true];
}
//- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
//    if([keyPath isEqualToString:@"title"]){
//        self.wdjTitleLab.text = _wdjWebView.title;
//    }
//}
@end
